package com.itheima.mapper;

import com.itheima.domain.Trip;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @Name TripMapper
 * @Author BaiXin
 * @Date 2022-10-16 18:22
 */

public interface TripMapper {

    /**
     * 查询所有
     * @return
     */
    @Select("select id, username, gender, idcard, from_address, to_address, start_time from tb_trip")
    @Results(
            id = "ResultMap",
            value = {
                    @Result(id = true,column = "id",property = "id"),
                    @Result(column = "username",property = "username"),
                    @Result(column = "gender",property = "gender"),
                    @Result(column = "idcard",property = "idcard"),
                    @Result(column = "from_address",property = "fromAddress"),
                    @Result(column = "to_address",property = "toAddress"),
                    @Result(column = "start_time",property = "startTime"),
            }
    )

    List<Trip> findAll();

    /**
     * 添加行程
     * @param trip
     */
    @Insert("insert into tb_trip (username, gender, idcard, from_address, to_address, start_time) " +
            "values (#{username},#{gender},#{idcard},#{fromAddress},#{toAddress},#{startTime})")
    void add(Trip trip);

    /**
     * 根据id查询用户的行程数据
     * @param id
     * @return
     */
    @Select("select id, username, gender, idcard, from_address, to_address, start_time from tb_trip where id = #{id}")
    @ResultMap("ResultMap")
    Trip findById(Integer id);

    /**
     * 修改
     * @param trip
     */
    void updateById(Trip trip);

    /**
     * 根据id删除
     * @param id
     */
    @Delete("delete from tb_trip where id = #{id}")
    void deleteById(Integer id);

}
